//
//  YHToolbar.swift
//  XLWB
//
//  Created by key on 16/6/29.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class YHToolbar: UIView {

    //MARK: - 数据传输
    var status: YHHomeList? {
        
        didSet{
            
            reposts?.setTitle(status?.reposts, forState: UIControlState.Normal)
            
            comments?.setTitle(status?.comments, forState: UIControlState.Normal)
            
            attitudes?.setTitle(status?.attitudes, forState: UIControlState.Normal)
            
            
        }
  
    }
    
    
    //MARK: - 转发 评论 赞 三控件
    //	int	转发数
    var reposts: UIButton?
    //	int	评论数
    var comments: UIButton?
    //	int	赞数
    var attitudes: UIButton?
    
    // 分割线
    var line1: UIImageView?
    
    var line2: UIImageView?
    
    
    //MARK: - 入口
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        //添加子控件
        //转发
        reposts = addSubButtonView("转发", imgName: "timeline_icon_retweet")
        //评论
        comments = addSubButtonView("评论", imgName: "timeline_icon_comment")
        //赞
        attitudes = addSubButtonView("赞", imgName: "timeline_icon_unlike")
        //分割线
        line1 = addSublineView()
        
        line2 = addSublineView()
        
        
        //添加约束
        setSubViewFrame()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    //MARK: - 添加 转发 评论 赞 三控件
    func addSubButtonView(title: String, imgName: String) -> UIButton? {
        
        
        //创建
        let button = UIButton()
        
        
        //设置
        button.setTitle(title, forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        
        //添加
        self.addSubview(button)
        
        
        return button
        
    }
    
    //分割线
    func addSublineView() -> UIImageView {
        
        let line = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(line)
        
        return line
    }
    
    //添加约束
    func setSubViewFrame() {
        
        //转发
        reposts?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.leading.top.bottom.equalTo(self)
            
            make.width.equalTo(comments!)
        })
        
        //评论
        comments?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            
            make.leading.equalTo(reposts!.snp_trailing)
            
            make.width.equalTo(attitudes!)
            
            
        })
        
        //赞
        attitudes?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.trailing.top.bottom.equalTo(self)
            
            make.leading.equalTo(comments!.snp_trailing)
            
            make.width.equalTo(attitudes!)
            
        })
        
        
        //分割线
        line1?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.centerX.equalTo(reposts!.snp_trailing)
            make.centerY.equalTo(self)
        })
        
        line2?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.centerX.equalTo(comments!.snp_trailing)
            make.centerY.equalTo(self)
        })
        
        
    }
    
    

    
    
    
    

}
